package com.frejoys.admin.controller;

import cn.hutool.core.bean.BeanUtil;
import com.frejoys.common.aop.Authority;
import com.frejoys.common.aop.Authorization;
import com.frejoys.common.constant.CommonConstant;
import com.frejoys.common.dto.admin.ReasonAddDto;
import com.frejoys.common.dto.admin.ReasonListDto;
import com.frejoys.common.dto.admin.ReasonSelectListDto;
import com.frejoys.common.dto.admin.ReasonUpDto;
import com.frejoys.common.response.Result;
import com.frejoys.common.vo.admin.ReasonVo;
import com.frejoys.dao.entity.Reason;
import com.frejoys.service.ReasonService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Tag(name = "驳回原因管理", description = "驳回原因管理")
@RestController
@RequiredArgsConstructor
@RequestMapping(CommonConstant.routePrefixAdmin)
@Authorization(Authority.Private)
public class AdminReasonController {

    private final ReasonService reasonService;

    @Operation(summary = "驳回原因列表")
    @PostMapping("/reason/list")
    public Result<List<ReasonVo>> storeList(@RequestBody @Validated ReasonListDto dto) {
        List<Reason> reasons = reasonService.listInfo(dto);
        List<ReasonVo> reasonVos = BeanUtil.copyToList(reasons, ReasonVo.class);
        return Result.success(reasonVos);
    }

    @Operation(summary = "驳回原因选择列表")
    @PostMapping("/reason/selectList")
    public Result<List<ReasonVo>> selectList(@RequestBody @Validated ReasonSelectListDto dto) {
        List<Reason> reasons = reasonService.listInfo(dto.getType());
        List<ReasonVo> reasonVos = BeanUtil.copyToList(reasons, ReasonVo.class);
        return Result.success(reasonVos);
    }

    @Operation(summary = "添加驳回原因")
    @PostMapping("/reason/addInfo")
    public Result addInfo(@RequestBody @Validated ReasonAddDto dto) {
        reasonService.addInfo(dto);
        return Result.success();
    }

    @Operation(summary = "编辑驳回原因")
    @PostMapping("/reason/upInfo")
    public Result upInfo(@RequestBody @Validated ReasonUpDto dto) {
        reasonService.upInfo(dto);
        return Result.success();
    }





}
